﻿/*
* 
*
* 功 能： N/A
* 类 名： BDDTWELL
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* 
*/
using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;

using DQYT.HTDZ.IDAL;
using Maticsoft.DBUtility;
using DQYT.HTDZ.Model;

namespace DQYT.HTDZ.OracleDAL
{
	/// <summary>
	/// 数据访问类:BDDTWELL
	/// </summary>
	public partial class BDDTWELLDAL:IBDDTWELL
	{
		public BDDTWELLDAL()
		{}
		#region  BasicMethod

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(decimal ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from BDDTWELL");
			strSql.Append(" where ID=:ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":ID", OracleType.Number,22)			};
			parameters[0].Value = ID;

			return DbHelperOra.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(BDDTWELLModel model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into BDDTWELL(");
			strSql.Append("ID,WELLID,JCRQ,BX,CC,CCI,RCYL,HS,RCYOL,DYM,CMD,YY,TY,CYFS,BJ)");
			strSql.Append(" values (");
            strSql.Append("HTDZ_ID.nextval,:WELLID,:JCRQ,:BX,:CC,:CCI,:RCYL,:HS,:RCYOL,:DYM,:CMD,:YY,:TY,:CYFS,:BJ)");
			OracleParameter[] parameters = {
					new OracleParameter(":WELLID", OracleType.VarChar,30),
					new OracleParameter(":JCRQ", OracleType.DateTime),
					new OracleParameter(":BX", OracleType.Float,22),
					new OracleParameter(":CC", OracleType.Float,22),
					new OracleParameter(":CCI", OracleType.Float,22),
					new OracleParameter(":RCYL", OracleType.Float,22),
					new OracleParameter(":HS", OracleType.Float,22),
					new OracleParameter(":RCYOL", OracleType.Float,22),
					new OracleParameter(":DYM", OracleType.Float,22),
					new OracleParameter(":CMD", OracleType.Float,22),
					new OracleParameter(":YY", OracleType.Float,22),
					new OracleParameter(":TY", OracleType.Float,22),
					new OracleParameter(":CYFS", OracleType.VarChar,30),
					new OracleParameter(":BJ", OracleType.VarChar,300)};
			parameters[0].Value = model.ID;
			parameters[1].Value = model.WELLID;
			parameters[2].Value = model.JCRQ;
			parameters[3].Value = model.BX;
			parameters[4].Value = model.CC;
			parameters[5].Value = model.CCI;
			parameters[6].Value = model.RCYL;
			parameters[7].Value = model.HS;
			parameters[8].Value = model.RCYOL;
			parameters[9].Value = model.DYM;
			parameters[10].Value = model.CMD;
			parameters[11].Value = model.YY;
			parameters[12].Value = model.TY;
			parameters[13].Value = model.CYFS;
			parameters[14].Value = model.BJ;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(BDDTWELLModel model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update BDDTWELL set ");
			strSql.Append("WELLID=:WELLID,");
			strSql.Append("JCRQ=:JCRQ,");
			strSql.Append("BX=:BX,");
			strSql.Append("CC=:CC,");
			strSql.Append("CCI=:CCI,");
			strSql.Append("RCYL=:RCYL,");
			strSql.Append("HS=:HS,");
			strSql.Append("RCYOL=:RCYOL,");
			strSql.Append("DYM=:DYM,");
			strSql.Append("CMD=:CMD,");
			strSql.Append("YY=:YY,");
			strSql.Append("TY=:TY,");
			strSql.Append("CYFS=:CYFS,");
			strSql.Append("BJ=:BJ");
			strSql.Append(" where ID=:ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":WELLID", OracleType.VarChar,30),
					new OracleParameter(":JCRQ", OracleType.DateTime),
					new OracleParameter(":BX", OracleType.Float,22),
					new OracleParameter(":CC", OracleType.Float,22),
					new OracleParameter(":CCI", OracleType.Float,22),
					new OracleParameter(":RCYL", OracleType.Float,22),
					new OracleParameter(":HS", OracleType.Float,22),
					new OracleParameter(":RCYOL", OracleType.Float,22),
					new OracleParameter(":DYM", OracleType.Float,22),
					new OracleParameter(":CMD", OracleType.Float,22),
					new OracleParameter(":YY", OracleType.Float,22),
					new OracleParameter(":TY", OracleType.Float,22),
					new OracleParameter(":CYFS", OracleType.VarChar,30),
					new OracleParameter(":BJ", OracleType.VarChar,300),
					new OracleParameter(":ID", OracleType.Number,18)};
			parameters[0].Value = model.WELLID;
			parameters[1].Value = model.JCRQ;
			parameters[2].Value = model.BX;
			parameters[3].Value = model.CC;
			parameters[4].Value = model.CCI;
			parameters[5].Value = model.RCYL;
			parameters[6].Value = model.HS;
			parameters[7].Value = model.RCYOL;
			parameters[8].Value = model.DYM;
			parameters[9].Value = model.CMD;
			parameters[10].Value = model.YY;
			parameters[11].Value = model.TY;
			parameters[12].Value = model.CYFS;
			parameters[13].Value = model.BJ;
			parameters[14].Value = model.ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(decimal ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from BDDTWELL ");
			strSql.Append(" where ID=:ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":ID", OracleType.Number,22)			};
			parameters[0].Value = ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from BDDTWELL ");
			strSql.Append(" where ID in ("+IDlist + ")  ");
			int rows=DbHelperOra.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public BDDTWELLModel GetModel(decimal ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,WELLID,JCRQ,BX,CC,CCI,RCYL,HS,RCYOL,DYM,CMD,YY,TY,CYFS,BJ from BDDTWELL ");
			strSql.Append(" where ID=:ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":ID", OracleType.Number,22)			};
			parameters[0].Value = ID;

			BDDTWELLModel model=new BDDTWELLModel();
			DataSet ds=DbHelperOra.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public BDDTWELLModel DataRowToModel(DataRow row)
		{
			BDDTWELLModel model=new BDDTWELLModel();
			if (row != null)
			{
				if(row["ID"]!=null && row["ID"].ToString()!="")
				{
					model.ID=decimal.Parse(row["ID"].ToString());
				}
				if(row["WELLID"]!=null)
				{
					model.WELLID=row["WELLID"].ToString();
				}
				if(row["JCRQ"]!=null && row["JCRQ"].ToString()!="")
				{
					model.JCRQ=DateTime.Parse(row["JCRQ"].ToString());
				}
				if(row["BX"]!=null && row["BX"].ToString()!="")
				{
					model.BX=decimal.Parse(row["BX"].ToString());
				}
				if(row["CC"]!=null && row["CC"].ToString()!="")
				{
					model.CC=decimal.Parse(row["CC"].ToString());
				}
				if(row["CCI"]!=null && row["CCI"].ToString()!="")
				{
					model.CCI=decimal.Parse(row["CCI"].ToString());
				}
				if(row["RCYL"]!=null && row["RCYL"].ToString()!="")
				{
					model.RCYL=decimal.Parse(row["RCYL"].ToString());
				}
				if(row["HS"]!=null && row["HS"].ToString()!="")
				{
					model.HS=decimal.Parse(row["HS"].ToString());
				}
				if(row["RCYOL"]!=null && row["RCYOL"].ToString()!="")
				{
					model.RCYOL=decimal.Parse(row["RCYOL"].ToString());
				}
				if(row["DYM"]!=null && row["DYM"].ToString()!="")
				{
					model.DYM=decimal.Parse(row["DYM"].ToString());
				}
				if(row["CMD"]!=null && row["CMD"].ToString()!="")
				{
					model.CMD=decimal.Parse(row["CMD"].ToString());
				}
				if(row["YY"]!=null && row["YY"].ToString()!="")
				{
					model.YY=decimal.Parse(row["YY"].ToString());
				}
				if(row["TY"]!=null && row["TY"].ToString()!="")
				{
					model.TY=decimal.Parse(row["TY"].ToString());
				}
				if(row["CYFS"]!=null)
				{
					model.CYFS=row["CYFS"].ToString();
				}
				if(row["BJ"]!=null)
				{
					model.BJ=row["BJ"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,WELLID,JCRQ,BX,CC,CCI,RCYL,HS,RCYOL,DYM,CMD,YY,TY,CYFS,BJ ");
			strSql.Append(" FROM BDDTWELL ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOra.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM BDDTWELL ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.ID desc");
			}
			strSql.Append(")AS Row, T.*  from BDDTWELL T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperOra.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "BDDTWELL";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

